<?php
namespace Common\Controller;
use Base\Controller;
use User\Event\UserEvent;

class PrivateController extends Controller {
	//当前用户
	var $user=array();
	var $user_id;
	//网站相关配置
	var $config=array();
	// 分页展示数
	protected $limit = 20;
	//缓存时间 s
	protected $cacheTime = 120;
	//登录信息
	protected $loginInfo;
	//内容类型
	protected $contentType = array(
		'idea'  =>  1,  //灵感
		'ask'   =>  2,  //问答
	);

	//行为类型
	protected $actionType = array(
		'browse'	=>	1,
		'praise'	=>	2,
		'thank'		=>	3,
		'comment'	=>	4,
		'attention'	=>	6,
	);

	//消息类型
	protected $msgType = array(
		'sender'	=>	0,	//发送者
		'recipient'	=>	1,	//接受者
	);

	protected  function _initialize() {
		parent::_initialize();
		if (!$_SESSION["user"]) {
			$_SESSION["back_url"] = __SELF__;
			if( IS_AJAX ) {
				$this->returnResult(-999, '没有访问权限！');
			} else {
				$this->redirect('/', array(), 0, '');
			}
			return false;
		}
		if(is_file('./site.inc.php')) {
			$this->config = @include('./site.inc.php');
		} else {
			$common = '//站点配置文件';
			$this->config = M('SystemConfig')->getField('code,value');
			$content  = "<?php \n".$common."\nreturn ".var_export($this->config,true).";\n?>";
			file_put_contents('./site.inc.php',$content);
		}
		$this->user		=	unserialize(stripcslashes($_SESSION["user"]));
		$this->user_id	=	intval($this->user['user_id']);
		$userEvent = new UserEvent();
		$statistic = $userEvent->userBaseStatistic( $this->user_id );
		$this->user = array_merge( $this->user, $statistic );
		$this->loginInfo = &$this->user;
		$this->assign("user", $this->user);
		$this->assign("login_flag", empty($this->user) ? 'false' : 'true');
		$this->assign("config",$this->config);
    }


}

